package com.xc58.highreactor.seril;

import static com.xc58.highreactor.util.ByteUtil.getByteFormShort;
import static com.xc58.highreactor.util.ByteUtil.toShort;

import java.io.InputStream;

import com.xc58.highreactor.exception.ParseDataException;

public class CharSerializer implements ISerializer<Character> {

	public byte[] serialize(Character rawObject) throws Exception {
		return getByteFormShort((short)rawObject.charValue());
	}

	public Character deserialize(InputStream input) throws Exception {
		byte[] bytes = new byte[2];
		if(input.read(bytes) < 2){
			throw new ParseDataException();
		}
		return (char)toShort(bytes);
	}

}
